package org.example.common.exception;


import lombok.Getter;
import org.example.common.enums.BusinessErrorCode;

/**
 * 业务异常
 * 当发生业务异常直接新建并抛出
 */
public class BusinessException extends RuntimeException {

    @Getter
    private final BusinessErrorCode errorCode;

    // 封装错误消息
    public BusinessException(String message) {
        super(message);
        this.errorCode = BusinessErrorCode.UNKNOWN_ERROR;
        return;
    }

    // 封装返回码和错误消息
    public BusinessException(BusinessErrorCode resultCode) {
        super(resultCode.getMessage());
        this.errorCode = resultCode;
    }

    // 封装返回码、错误消息和异常栈
    public BusinessException(BusinessErrorCode resultCode, Throwable cause) {
        super(cause);
        this.errorCode = resultCode;
    }
}
